package com.example.gym_manage_system.view.backstage.mainView;

import com.example.gym_manage_system.tools.GetProps;
import com.example.gym_manage_system.view.backstage.mainView.bookView.BookView;
import com.example.gym_manage_system.view.backstage.mainView.noticeView.NoticeView;
import com.example.gym_manage_system.view.backstage.mainView.siteTypeView.SiteTypeView;
import com.example.gym_manage_system.view.backstage.mainView.siteView.SiteView;
import com.example.gym_manage_system.view.backstage.mainView.userView.UserView;
import com.example.gym_manage_system.view.components.button.MyButton;
import com.example.gym_manage_system.view.components.frame.MyFrame;

import javax.swing.*;
import java.util.Properties;

/**
 * @author qzy
 * @description 描述
 * @create 2023-12-13 14:36
 */
public class MainView {
    private static final Properties props = GetProps.init();
    private static final String systemName = props.getProperty("system_name");
    private static final String[] menus = {"用户管理", "场地管理", "预订管理", "类型管理", "公告管理", "系统管理"};
    private static final JPanel[] panels = {
            new UserView(),
            SiteView.createSiteView(),
            BookView.createBookView(),
            SiteTypeView.createSiteTypeView(),
            NoticeView.createNoticeView()
    };
    private static JSplitPane splitPane;

    public static void createMainView() {
        JFrame frame = new MyFrame(systemName);

        JPanel leftPanel = createLeftPanel();

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, panels[0]);
        splitPane.setDividerLocation(120);

        frame.add(splitPane);
        frame.setVisible(true);
    }

    public static JPanel createLeftPanel() {
        JPanel panel = new JPanel();
        JButton userBtn = MyButton.infoBtn(menus[0]);
        JButton siteBtn = MyButton.infoBtn(menus[1]);
        JButton bookBtn = MyButton.infoBtn(menus[2]);
        JButton siteTypeBtn = MyButton.infoBtn(menus[3]);
        JButton noticeBtn = MyButton.infoBtn(menus[4]);

        userBtn.addActionListener(e -> setPanel(0));
        siteBtn.addActionListener(e -> setPanel(1));
        bookBtn.addActionListener(e -> setPanel(2));
        siteTypeBtn.addActionListener(e -> setPanel(3));
        noticeBtn.addActionListener(e -> setPanel(4));

        panel.add(userBtn);
        panel.add(siteBtn);
        panel.add(bookBtn);
        panel.add(siteTypeBtn);
        panel.add(noticeBtn);
        return panel;
    }

    public static void setPanel(int index) {
        splitPane.setRightComponent(panels[index]);
        splitPane.setDividerLocation(120);
    }
}
